package org.liquidByte.trafficMustang.androidApp.listview.adapter;

import org.liquidByte.trafficMustang.R;
import org.liquidByte.trafficMustang.androidApp.listview.row.AceiteRow;
import org.liquidByte.trafficMustang.androidApp.listview.row.ListViewRow;
import org.liquidByte.trafficMustang.androidApp.listview.row.RowActionListener;
import org.liquidByte.trafficMustang.androidApp.services.dto.TrechoDTO;

import android.content.Context;
import android.view.View;

public class AceiteRowAdapter extends RowAdapter<TrechoDTO> {

	private RowActionListener<AceiteRow> negarActionListener;
	private RowActionListener<AceiteRow> confirmarActionListener;
	
	protected AceiteRowAdapter(Context ctx) {
		super(ctx);
	}

	@Override
	public long getItemId(int position) {
		TrechoDTO trecho = (TrechoDTO)this.getItem(position);
		if (trecho == null) {
			return 0;
		} else {
			return trecho.getId();
		}
	}
	
	public void setNegarActionListener(RowActionListener<AceiteRow> negarActionListener) {
		this.negarActionListener = negarActionListener;
	}

	public void setConfirmarActionListener(RowActionListener<AceiteRow> confirmarActionListener) {
		this.confirmarActionListener = confirmarActionListener;
	}

	@Override
	protected int getViewResource() {
		return R.layout.listview_row_aceite;
	}

	@Override
	protected ListViewRow createRow(View view) {
		AceiteRow row = new AceiteRow(this, view);
		row.setConfirmarActionListener(new RowActionListener<AceiteRow>() {
			@Override
			public void actionPerformed(AceiteRow row) {
				AceiteRowAdapter adapter = AceiteRowAdapter.this;
				if (adapter.confirmarActionListener != null) {
					adapter.confirmarActionListener.actionPerformed(row);
				}
			}
		});
		row.setNegarActionListener(new RowActionListener<AceiteRow>() {
			
			@Override
			public void actionPerformed(AceiteRow row) {
				AceiteRowAdapter adapter = AceiteRowAdapter.this;
				if (adapter.negarActionListener != null) {
					adapter.negarActionListener.actionPerformed(row);
				}				
			}
		});
		return row;
	}

}
